<?php
/**
 * Created by PhpStorm.
 * User: wu
 * Date: 2016/4/5
 * Time: 21:23
 */
namespace Home\Pay;
/**
 * 网银在线<chinabank.com.cn> 支付类
 */
class CBPay {
    protected $v_mid;
    protected $paykey;
    protected $v_md5info;
    protected $v_url;
    public $v_moneytype = 'CNY';
    public $v_oid;
    public $v_amount;
    public function __construct() {
    // 商户号,支付密钥,回调地址写在配置文件中
        $this->v_mid = C('v_mid');
        $this->paykey = C('paykey');
        $this->v_mid = C('v_url');
    } 
    public function form() {
        $this->crypt(); // 生成数字签名
        $str = '<form method=post action="https://pay3.chinabank.com.cn/PayGate">
        <input type=hidden name=v_mid value="%s">
        <input type=hidden name=v_oid value="%s">
        <input type=hidden name=v_amount value="%s">
        <input type=hidden name=v_moneytype value="%s">
        <input type=hidden name=v_url value="%s">
        <input type=hidden name=v_md5info value="%s">
        <input type="submit" value="支付" />
        </form>';
        return sprintf($str , $this->v_mid , $this->v_oid , $this->v_amount , $this->v_moneytype , $this->v_url , $this->v_md5info);
    } 
    public function crypt() {
        $str = $this->v_amount.$this->v_moneytype.$this->v_oid.$this->v_mid.$this->v_url.$this->paykey;
        $this->v_md5info = strtoupper(md5($str));
    }   
}